package com.chuyh.libraries.test

import android.app.Application
import android.util.TypedValue
import com.hjq.toast.Toaster

/*
 * ---------------------------------------------------------------------------------------------
 * ---------------------------------------------------------------------------------------------
 * need to init
 * ---------------------------------------------------------------------------------------------
 * ---------------------------------------------------------------------------------------------
 */
internal lateinit var application: Application

fun Application.initTestTools() {
    application = this
    Toaster.init(this)
}

/*
 * ---------------------------------------------------------------------------------------------
 * ---------------------------------------------------------------------------------------------
 * tools-dp
 * ---------------------------------------------------------------------------------------------
 * ---------------------------------------------------------------------------------------------
 */
private val metrics by lazy { application.resources.displayMetrics }

val Int.dp: Int
    get() = this.toFloat().applyDimension().toInt()

val Int.dpf: Float
    get() = this.toFloat().applyDimension()

private fun Float.applyDimension() = TypedValue.applyDimension(TypedValue.COMPLEX_UNIT_DIP, this, metrics)

/*
 * ---------------------------------------------------------------------------------------------
 * ---------------------------------------------------------------------------------------------
 * tools-toast
 * ---------------------------------------------------------------------------------------------
 * ---------------------------------------------------------------------------------------------
 */
fun String.toast(): Unit = Toaster.show(this)
